<link href="/css/default.css" rel="stylesheet" type="text/css" />
<link href="/css/uploadify.css" rel="stylesheet" type="text/css" />

<script type="text/javascript" src="./js/swfobject.js"></script>
<script type="text/javascript" src="./js/jquery.uploadify.v2.1.0.min.js"></script>
<script type="text/javascript">


var uploadQueue = new Array();

function startUpload () {
    $.each(uploadQueue, function(k, v){
          $('#uploadify').uploadifySettings('scriptData',{'description':$('#desc_'+v).val()});
        $('#uploadify').uploadifyUpload(v);
    });
    uploadQueue = new Array();
}


$(document).ready(function() {

   $("#uploadify").uploadify({
      'uploader'         : './js/uploadify.swf',
      'script'         : './js/uploadify.php',
      'cancelImg'       : './img/cancel.png',
      'folder'         : 'dok_zew/<?php echo $_SESSION['wyb_pac_id'];?>',
      'queueID'         : 'fileQueue',
      'auto'            : false,
      'multi'            : true,
      //'checkScript'      : 'scripts/check.php',
      'buttonText'      : 'Wybierz',
      'queueSizeLimit'   : 20,
      'currentfilecount'   : 20,
      'simUploadLimit'   : '10',
      'onAllComplete'      : function(e, d) {
                        var message = d.errors + ' errors and ' + d.filesUploaded + ' successful.'; },
      'onSelect'         : function(event, queueID, fileObj) {
                           uploadQueue.push(queueID);
                           //alert(queueID);
		
                        } ,
		'onComplete': function() {
		location.reload();
}
   });
});
</script>
<?
$handle = @opendir('./dok_zew/'.$_SESSION['wyb_pac_id']);
#if ($handle = opendir('c:/wamp/www/darmedicus/dok_zew/'.$_SESSION['wyb_pac_id'])) {
if ($handle==FALSE) {
	@mkdir('./dok_zew/'.$_SESSION['wyb_pac_id']);
	#@mkdir('./dok_zew/'.$_SESSION['wyb_pac_id'].'/'.$_SESSION['wyb_wiz_ed']);
	}
#}
if ($handle = opendir('./dok_zew/'.$_SESSION['wyb_pac_id'])) {
   
    echo "Pliki:<br>";

    /* To jest poprawna metoda  */
	$nr=0;
    while (false !== ($file = readdir($handle))) { 
        if ($file=='.' || $file=='..') echo '';
    	#if ($nr==0) echo(' ');
		#elseif($nr==1) echo(' ');
		else echo '<a href="dok_zew/'.$_SESSION['wyb_pac_id'].'/'.$file.'" target="_blank">'.$file.'</a><br>';
    $nr++;
	}
    closedir($handle); 
}
echo '<hr>';
?>
<div id="fileQueue"></div>
<input type="file" name="uploadify" id="uploadify" />
<a href="javascript:jQuery('#uploadify').uploadifyClearQueue()"><font color=#ff0000>Anuluj</font></a>
<a href="javascript:startUpload()">Wczytaj</a>
<?php
echo '<form>'; 
?>
